local RadarWidget = class("RadarDrawNode")
function RadarWidget:ctor(parentNode, radius, pointNum, zeroFactory, downFactory)

    -- 计算个点位置
    local dxA = 360/pointNum
    local points = {}
    local mathSin = math.sin
    local mathCos = math.cos
    local mathRad = math.rad
    for i = 1, pointNum do
        local a = dxA * (i - 1)
        local p = {}
        p.x = mathSin(mathRad(a)) * radius
        p.y = mathCos(mathRad(a)) * radius
        table.insert(points, p)
    end

    self._zeroFactory = zeroFactory or 0
    self._downFactory = downFactory or 0
    
    self._borderColor = cc.c4f(1, 0.96, 0.54, 0.8)
    self._bgColor = cc.c4f(1, 0.82, 0.23, 0.8)
    self._borderWidth = 1
    -- self._parentNode = parentNode
    local drawNode = cc.DrawNode:create()
    self._drawNode = drawNode
    self._points = points
    self._pointNum = pointNum
    parentNode:addChild(drawNode)
end 


function RadarWidget:setLineColor(color)
    self._borderColor = color
end

function RadarWidget:setBgColor(color)
    self._bgColor = color
end

function RadarWidget:setBorderWidth(width)
    self._borderWidth = width
end

-- baseScale 当前比例 
-- scale 为保证突显雷达图形状 假如偏移值
function RadarWidget:setData(d)
    self._drawNode:clear()
    local nPts = {}

    local zeroFactory = self._zeroFactory
    local downFactory = self._downFactory

    for k, v in ipairs(self._points) do
        local s = d.scale[k] or 1
        local rs = (1 - zeroFactory) * d.baseScale + zeroFactory - downFactory * s
        table.insert(nPts, {x = v.x*rs, y = v.y*rs})
    end

    self._drawNode:drawPolygonFunc(nPts, {
        fillColor = self._bgColor,
        borderWidth = self._borderWidth,
        borderColor = self._borderColor
    })
end

return RadarWidget